/**
 * Created by Administrator on 15-10-22.
 */
var ListManager = RichBase.extend({
	statics : {
		MAX_TICKETUL_SIZE : 3
	},
	EVENTS : {
		"click" : {
			".ticTypeToggleBtn" : "onTicTypeToggleBtnClick",
			".slideTicketUlBtn" : "onSlideTicketUlBtnClick"
		}
	},
	onTicTypeToggleBtnClick : function(that,e){
		var tarBtn = $(e.currentTarget);
		var parent = tarBtn.parents(".line");
		var tipBox = parent.children(".ticketTypeMsgBox");
		tarBtn.toggleClass("on");
		tipBox.slideToggle();
	},
	onSlideTicketUlBtnClick : function(that,e){
		var tarBtn = $(e.currentTarget);
		if(tarBtn.hasClass("disable")) return e.stopPropagation();
		tarBtn.toggleClass("on");
		var ticketUl = tarBtn.prev(".ticketUl");
		var oHeight = ticketUl.attr("data-oheight");
		var sHeight = ticketUl.attr("data-sheight");
		var tarHeight = tarBtn.hasClass("on") ? "auto" : sHeight;
		ticketUl.animate({height:tarHeight});
	},
	init : function(opt){
		this.container = opt.container;
		this.autoFixTicketUl()
	},
	autoFixTicketUl : function(){
		var that = this;
		var MAX_TICKETUL_SIZE = this.statics.MAX_TICKETUL_SIZE;
		this.container.children().children(".ticketBox").children(".ticketUl").each(function(){
			var tarUl = $(this);
			var lines = tarUl.children();
			var line_len = lines.length;
			if(line_len>MAX_TICKETUL_SIZE){
				var lineHeight = lines.first().height();
				var sHeight = lineHeight * MAX_TICKETUL_SIZE + 3;
				var oHeight = (lineHeight+1) * line_len;
				tarUl.height(sHeight).attr("data-oheight",oHeight).attr("data-sheight",sHeight);
			}else{
				tarUl.next(".slideTicketUlBtn").addClass("disable");
			}
		})
	}
});
module.exports = ListManager;